package com.zy.ivideo.service;

import com.zy.ivideo.entity.ResponseEntity;
import com.zy.ivideo.entity.VideoTypeEntity;
import com.zy.ivideo.repository.VideoTypeRepository;
import com.zy.ivideo.utils.ResponseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.persistence.EntityManager;
import javax.persistence.Query;
import java.util.List;

@Service
public class VideoTypeService {
    @Autowired
    VideoTypeRepository videoTypeRepository;

    @Autowired
    EntityManager entityManager;

    /**
     * 获取Simple视频类型信息
     * @return
     */
    public ResponseEntity<List<VideoTypeEntity>> getSimpleType(){
        String sql="select * from b_videotype where haschild=0 and channelid!=''";
        Query query = entityManager.createNativeQuery(sql, VideoTypeEntity.class);
        List resultList = query.getResultList();
        if (resultList==null||resultList.size()==0){
            return ResponseUtils.failed("没有获取到视频类型信息");
        }
        return ResponseUtils.success(resultList);
    }

    /**
     * 获取Mutil视频类型信息
     * @return
     */
    public ResponseEntity<List<VideoTypeEntity>> getMutilType(){
        String sql="select * from b_videotype where haschild=1";
        Query query = entityManager.createNativeQuery(sql, VideoTypeEntity.class);
        List resultList = query.getResultList();
        if (resultList==null||resultList.size()==0){
            return ResponseUtils.failed("没有获取到视频类型信息");
        }
        return ResponseUtils.success(resultList);
    }

    /**
     * 根据上级id获取Mutil视频类型信息
     * @return
     */
    public ResponseEntity<List<VideoTypeEntity>> getMutilTypeByPid(int pid){
        String sql="select * from b_videotype where pid="+pid;
        Query query = entityManager.createNativeQuery(sql, VideoTypeEntity.class);
        List resultList = query.getResultList();
        if (resultList==null||resultList.size()==0){
            return ResponseUtils.failed("没有获取到视频类型信息");
        }
        return ResponseUtils.success(resultList);
    }
}
